package com.example.myapplication.request

import androidx.lifecycle.MutableLiveData
import com.example.myapplication.bean.ListResultBean
import com.example.myapplication.bean.article.ArticleBean
import com.example.myapplication.bean.collect.WebsiteCollectBean
import com.kun.base.net.Api
import com.kun.base.net.ResponseResult

/**
 *搜索相关的request
 *
 * @author : Kun
 * @date : 2021/6/9
 * @time : 15:16
 */
class SearchRequest {
    /**
     * 搜索热词
     */
    val hotKeyResult = MutableLiveData<ResponseResult<List<WebsiteCollectBean>>>()

    /**
     * 搜索结果
     */
    val searchListResult = MutableLiveData<ResponseResult<ListResultBean<ArticleBean>>>()

    /**
     * 获取搜索热词
     */
    suspend fun requestHotKey() {
        hotKeyResult.value = Api.apiCall {
            Api.getInstance(IApi::class.java).getHotKey()
        }
    }

    /**
     * 请求搜索结果
     * @param index 页码
     * @param k 关键词
     */
    suspend fun requestSearchList(index: Int, k: String) {
        searchListResult.value = Api.apiCall {
            Api.getInstance(IApi::class.java).getSearchList(index, k)
        }
    }
}